package com.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.beans.CompteRenduActivite;
import com.beans.Projets;
import com.beans.Users;
import com.metier.CraMetier;
import com.metier.ProjetMetier;
import com.metier.UsersMetier;

public class PanelModifierCompteRenduActivite extends JPanel {

	private Date referencecraDateCreate ;
	private Users userlog ;
	private Projets projet ;
	private  Users userConnecter ;
	private  UsersMetier userMetier ;
	private String logrecuperer ,valeureSelectionner;

	private List<Projets> projetItems ;
	    private CraMetier crametier ;
	    public PanelModifierCompteRenduActivite() {
	        initComponents();
	    }

	    
	    @SuppressWarnings("unchecked")
	    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	    private void initComponents() {
	    	userConnecter = new Users ();
	        userMetier= new UsersMetier();
	        jLabel1 = new javax.swing.JLabel();
	        datedebut = new com.toedter.calendar.JDateChooser();
	        jLabel2 = new javax.swing.JLabel();
	        datefin = new com.toedter.calendar.JDateChooser();
	        jLabel3 = new javax.swing.JLabel();
	        textActivite = new javax.swing.JTextField();
	        jLabel4 = new javax.swing.JLabel();
	        textDuresPrevus = new javax.swing.JTextField();
	        jLabel5 = new javax.swing.JLabel();
	        textDuresEffect = new javax.swing.JTextField();
	        jLabel6 = new javax.swing.JLabel();
	        textProjet = new javax.swing.JTextField();
	        jLabel7 = new javax.swing.JLabel();
	        jScrollPane1 = new javax.swing.JScrollPane();
	        textCommentaire = new javax.swing.JTextArea();
	        boutonValider = new javax.swing.JButton();
	        boutonAnnuler = new javax.swing.JButton();
	        jLabel8 = new javax.swing.JLabel();
	        comboStatut = new javax.swing.JComboBox();

	        setBackground(new java.awt.Color(128, 130, 133));
	        setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(192, 36, 91)));
	        setForeground(new java.awt.Color(255, 255, 255));
	        setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        setMaximumSize(new java.awt.Dimension(1050, 385));
	        setMinimumSize(new java.awt.Dimension(1050, 385));

	        jLabel1.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel1.setText("Date Debut :");

	        jLabel2.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel2.setText("Date Fin :");

	        jLabel3.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel3.setText("Activite :");

	        jLabel4.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel4.setText("Durée Prévue :");

	        jLabel5.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel5.setText("Durée Effective  :");

	        jLabel6.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel6.setText("Projet :");

	        jLabel7.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel7.setText("Commentaire :");

	        textCommentaire.setColumns(20);
	        textCommentaire.setRows(5);
	        jScrollPane1.setViewportView(textCommentaire);

	        boutonValider.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        boutonValider.setText("VALIDER");
	        textDuresEffect.addKeyListener(new java.awt.event.KeyAdapter() {
				public void keyTyped(java.awt.event.KeyEvent e) {
					// System.out.println("keyTyped()"); // TODO
					// Auto-generated Event stub keyTyped()
					if ((e.getKeyChar() > '9') || (e.getKeyChar() < '0'))
						e.setKeyChar('\0');
				}

			});
	        textDuresPrevus.addKeyListener(new java.awt.event.KeyAdapter() {
				public void keyTyped(java.awt.event.KeyEvent e) {
					// System.out.println("keyTyped()"); // TODO
					// Auto-generated Event stub keyTyped()
					if ((e.getKeyChar() > '9') || (e.getKeyChar() < '0'))
						e.setKeyChar('\0');
				}

			});
	       

	        boutonValider.addActionListener(new ActionListener() {

				public void actionPerformed(ActionEvent arg0) {
					// TODO Auto-generated method stub
					if (JOptionPane.showConfirmDialog(getFrame(),
							"Voulez-vous vraiment confirmer la modification?",
							"Information", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
						crametier=new CraMetier();
						CompteRenduActivite craToModify = new CompteRenduActivite();
						Date refcraToModify = getReferencecraDateCreate();
						//craDateCreate
						 
						System.out.println(" voici la regerence correspondant au projet modifié  "+refcraToModify);
						craToModify = crametier.findCompteRenduActiviteByDate(refcraToModify);
						craToModify.setActDureEff(textDuresEffect.getText());
						craToModify.setActDurePrev(textDuresPrevus.getText());
						craToModify.setActProjet(textProjet.getText());
						craToModify.setActStatut(valeureSelectionner);
						craToModify.setCraDateDeb(datedebut.getDate());
						craToModify.setCraDateFin(datefin.getDate());
						craToModify.setCraDescription(textCommentaire.getText());
						crametier.testUpdate(craToModify);
						//crametier.updateCraMetier(craDateDebut, craDateFin, craprojEtat, cradureff, cradurprev, craactprojet, cracommentaire);
						textActivite.setText("");
						textCommentaire.setText("");
						textDuresPrevus.setText("");
						textDuresEffect.setText("");
						datefin.setDate(null);
						datedebut.setDate(null);
						

						JOptionPane.showMessageDialog(null, "Le compte rendu d'activité  a été bien modifié ");

					}

				}
			});
	        boutonAnnuler.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        boutonAnnuler.setText("ANNULER");

	        jLabel8.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
	        jLabel8.setText("Statut :");

	        comboStatut.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
	        comboStatut.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "En Cours ", "Standby", "Terminer", "Abadonner" }));
	        comboStatut.addActionListener(new ActionListener() {
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	               
	                Object source = comboStatut.getSelectedItem();
					valeureSelectionner= (String) source;
	            }
	        });

	        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
	        this.setLayout(layout);
	        layout.setHorizontalGroup(
	            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(layout.createSequentialGroup()
	                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addGroup(layout.createSequentialGroup()
	                        .addContainerGap()
	                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                            .addComponent(jLabel1)
	                            .addComponent(jLabel3)
	                            .addComponent(jLabel6)
	                            .addComponent(jLabel4))
	                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
	                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
	                            .addComponent(datedebut, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
	                            .addComponent(textActivite)
	                            .addComponent(textProjet)
	                            .addComponent(textDuresPrevus)))
	                    .addGroup(layout.createSequentialGroup()
	                        .addGap(269, 269, 269)
	                        .addComponent(boutonValider)))
	                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addGroup(layout.createSequentialGroup()
	                        .addGap(229, 229, 229)
	                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                            .addGroup(layout.createSequentialGroup()
	                                .addComponent(jLabel2)
	                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
	                            .addGroup(layout.createSequentialGroup()
	                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
	                                .addGap(55, 55, 55))
	                            .addGroup(layout.createSequentialGroup()
	                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                                    .addComponent(boutonAnnuler)
	                                    .addComponent(jLabel8))
	                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)))
	                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                            .addComponent(datefin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
	                            .addComponent(textDuresEffect, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
	                            .addComponent(comboStatut, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
	                        .addGap(67, 67, 67))
	                    .addGroup(layout.createSequentialGroup()
	                        .addGap(219, 219, 219)
	                        .addComponent(jLabel7)
	                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)))
	                .addGap(10, 10, 10))
	        );
	        layout.setVerticalGroup(
	            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(layout.createSequentialGroup()
	                .addContainerGap()
	                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addComponent(datedebut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                    .addComponent(jLabel1)
	                    .addComponent(jLabel2)
	                    .addComponent(datefin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
	                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
	                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
	                        .addComponent(jLabel4)
	                        .addComponent(textDuresPrevus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
	                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
	                        .addComponent(jLabel5)
	                        .addComponent(textDuresEffect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
	                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addGroup(layout.createSequentialGroup()
	                        .addGap(18, 18, 18)
	                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
	                            .addComponent(jLabel3)
	                            .addComponent(textActivite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
	                    .addGroup(layout.createSequentialGroup()
	                        .addGap(18, 18, 18)
	                        .addComponent(jLabel8))
	                    .addGroup(layout.createSequentialGroup()
	                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
	                        .addComponent(comboStatut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
	                .addGap(26, 26, 26)
	                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
	                        .addComponent(jLabel6)
	                        .addComponent(textProjet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                        .addComponent(jLabel7))
	                    .addGroup(layout.createSequentialGroup()
	                        .addGap(137, 137, 137)
	                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
	                            .addComponent(boutonValider)
	                            .addComponent(boutonAnnuler))))
	                .addContainerGap(81, Short.MAX_VALUE))
	        );
	    }// </editor-fold>//GEN-END:initComponents

	    private void comboStatutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboStatutActionPerformed
	        // TODO add your handling code here:
	    }//GEN-LAST:event_comboStatutActionPerformed

	    // Variables declaration - do not modify//GEN-BEGIN:variables
	    private javax.swing.JButton boutonAnnuler;
	    private javax.swing.JButton boutonValider;
	    private javax.swing.JComboBox comboStatut;
	    private com.toedter.calendar.JDateChooser datedebut;
	    private com.toedter.calendar.JDateChooser datefin;
	    private javax.swing.JLabel jLabel1;
	    private javax.swing.JLabel jLabel2;
	    private javax.swing.JLabel jLabel3;
	    private javax.swing.JLabel jLabel4;
	    private javax.swing.JLabel jLabel5;
	    private javax.swing.JLabel jLabel6;
	    private javax.swing.JLabel jLabel7;
	    private javax.swing.JLabel jLabel8;
	    private javax.swing.JScrollPane jScrollPane1;
	    private javax.swing.JTextField textActivite;
	    private javax.swing.JTextArea textCommentaire;
	    private javax.swing.JTextField textDuresEffect;
	    private javax.swing.JTextField textDuresPrevus;
	    private javax.swing.JTextField textProjet;
	    // End of variables declaration//GEN-END:variables
		/**
		 * @return the userlog
		 */
	    public JPanel getFrame() {
			return this;
		}
		public Users getUserlog() {
			return userlog;
		}
	public  void loadProject(){
		//projetItems=crametier.
	}
		/**
		 * @param userlog the userlog to set
		 */
		public void setUserlog(Users userlog) {
			this.userlog = userlog;
		}

		/**
		 * @return the projet
		 */
		public Projets getProjet() {
			return projet;
		}

		/**
		 * @return the userConnecter
		 */
		public Users getUserConnecter() {
			return userConnecter;
		}

		/**
		 * @param userConnecter the userConnecter to set
		 */
		public void setUserConnecter(Users userConnecter) {
			this.userConnecter = userConnecter;
		}

		/**
		 * @return the userMetier
		 */
		public UsersMetier getUserMetier() {
			return userMetier;
		}

		/**
		 * @param userMetier the userMetier to set
		 */
		public void setUserMetier(UsersMetier userMetier) {
			this.userMetier = userMetier;
		}

		/**
		 * @return the logrecuperer
		 */
		public String getLogrecuperer() {
			return logrecuperer;
		}

		/**
		 * @param logrecuperer the logrecuperer to set
		 */
		public void setLogrecuperer(String logrecuperer) {
			this.logrecuperer = logrecuperer;
		}

		/**
		 * @return the projetItems
		 */
		public List<Projets> getProjetItems() {
			return projetItems;
		}

		/**
		 * @param projetItems the projetItems to set
		 */
		public void setProjetItems(List<Projets> projetItems) {
			this.projetItems = projetItems;
		}

		/**
		 * @param projet the projet to set
		 */
		public void setProjet(Projets projet) {
			this.projet = projet;
		}

		/**
		 * @return the crametier
		 */
		public CraMetier getCrametier() {
			return crametier;
		}

		/**
		 * @param crametier the crametier to set
		 */
		public void setCrametier(CraMetier crametier) {
			this.crametier = crametier;
		}

		/**
		 * @return the boutonAnnuler
		 */
		public javax.swing.JButton getBoutonAnnuler() {
			return boutonAnnuler;
		}

		/**
		 * @param boutonAnnuler the boutonAnnuler to set
		 */
		public void setBoutonAnnuler(javax.swing.JButton boutonAnnuler) {
			this.boutonAnnuler = boutonAnnuler;
		}

		/**
		 * @return the boutonValider
		 */
		public javax.swing.JButton getBoutonValider() {
			return boutonValider;
		}

		/**
		 * @param boutonValider the boutonValider to set
		 */
		public void setBoutonValider(javax.swing.JButton boutonValider) {
			this.boutonValider = boutonValider;
		}

		/**
		 * @return the comboStatut
		 */
		public javax.swing.JComboBox getComboStatut() {
			return comboStatut;
		}

		/**
		 * @param comboStatut the comboStatut to set
		 */
		public void setComboStatut(javax.swing.JComboBox comboStatut) {
			this.comboStatut = comboStatut;
		}

		/**
		 * @return the datedebut
		 */
		public com.toedter.calendar.JDateChooser getDatedebut() {
			return datedebut;
		}

		/**
		 * @param datedebut the datedebut to set
		 */
		public void setDatedebut(com.toedter.calendar.JDateChooser datedebut) {
			this.datedebut = datedebut;
		}

		/**
		 * @return the datefin
		 */
		public com.toedter.calendar.JDateChooser getDatefin() {
			return datefin;
		}

		/**
		 * @param datefin the datefin to set
		 */
		public void setDatefin(com.toedter.calendar.JDateChooser datefin) {
			this.datefin = datefin;
		}

		/**
		 * @return the textActivite
		 */
		public javax.swing.JTextField getTextActivite() {
			return textActivite;
		}

		/**
		 * @param textActivite the textActivite to set
		 */
		public void setTextActivite(javax.swing.JTextField textActivite) {
			this.textActivite = textActivite;
		}

		/**
		 * @return the textCommentaire
		 */
		public javax.swing.JTextArea getTextCommentaire() {
			return textCommentaire;
		}

		/**
		 * @param textCommentaire the textCommentaire to set
		 */
		public void setTextCommentaire(javax.swing.JTextArea textCommentaire) {
			this.textCommentaire = textCommentaire;
		}

		/**
		 * @return the textDuresEffect
		 */
		public javax.swing.JTextField getTextDuresEffect() {
			return textDuresEffect;
		}

		/**
		 * @param textDuresEffect the textDuresEffect to set
		 */
		public void setTextDuresEffect(javax.swing.JTextField textDuresEffect) {
			this.textDuresEffect = textDuresEffect;
		}

		/**
		 * @return the textDuresPrevus
		 */
		public javax.swing.JTextField getTextDuresPrevus() {
			return textDuresPrevus;
		}

		/**
		 * @param textDuresPrevus the textDuresPrevus to set
		 */
		public void setTextDuresPrevus(javax.swing.JTextField textDuresPrevus) {
			this.textDuresPrevus = textDuresPrevus;
		}

		/**
		 * @return the textProjet
		 */
		public javax.swing.JTextField getTextProjet() {
			return textProjet;
		}

		/**
		 * @param textProjet the textProjet to set
		 */
		public void setTextProjet(javax.swing.JTextField textProjet) {
			this.textProjet = textProjet;
		}

		public Date getReferencecraDateCreate() {
			return referencecraDateCreate;
		}

		public void setReferencecraDateCreate(Date referencecraDateCreate) {
			this.referencecraDateCreate = referencecraDateCreate;
		}
	    

}
